package com.kaifamiao.deque;

import java.util.Deque;
import java.util.LinkedList;

public class DequeTest6 {

	public static void main(String[] args) {
		
		Deque<String> stack = new LinkedList<>();
		// 约定: 字符串形式的右侧为栈顶
		stack.offerLast( "刘彻" ); // 相当于将元素压入栈顶
		System.out.println( stack );
		
		stack.offerLast( "刘启" );
		System.out.println( stack );
		
		stack.offerLast( "刘恒" );
		System.out.println( stack );
		
		String top = stack.peekLast(); // 相当于检查栈顶元素(但不移除)
		System.out.println( top );
		System.out.println( stack );
		
		while( !stack.isEmpty() ) {
			top = stack.pollLast(); // 相当于弹出栈顶元素(并返回弹出的元素)
			System.out.println( top );
			System.out.println( stack );
		}
		
		System.out.println( "- - - - - - - - - - - - - - - - - - - - -" );
		
		// 约定: 字符串形式的左侧为栈顶
		stack.offerFirst( "回锅肉" ); // 相当于压栈
		stack.offerFirst( "盐煎肉" ); // 相当于压栈
		stack.offerFirst( "红烧肉" ); // 相当于压栈
		System.out.println( stack );
		
		System.out.println( stack.peekFirst() ); // 相当于检查栈顶元素
		System.out.println( stack );
		
		System.out.println( stack.pollFirst() ); // 相当于出栈
		System.out.println( stack );

	}

}
